package com.liucxu.jiandanl.Business;

import com.google.gson.Gson;
import com.liucxu.jiandanl.Consts.Urls;
import com.liucxu.jiandanl.Entity.Post;
import com.liucxu.jiandanl.Http.RequestManager;
import com.liucxu.jiandanl.Interface.RequestCallbackInterface;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * 获取新鲜事的Event
 * Created by liuchenxu on 2016/8/4.
 */
public class FreshNewsEvent extends BaseEvent {

    private String status;

    private int count;

    private int count_total;

    private int pages;

    private List<Post> posts ;

    public List<Post> getPosts() {
        return posts;
    }

    public void setPosts(List<Post> posts) {
        this.posts = posts;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getCount_total() {
        return count_total;
    }

    public void setCount_total(int count_total) {
        this.count_total = count_total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    /**
     * 获取新鲜事的方法
     * @param pageIndex
     */
    public static void GetRefreshNewsByPage(int pageIndex){

        RequestManager.GET(Urls.FRESH_NEWS_URL + pageIndex, new RequestCallbackInterface() {
            @Override
            public void onSuccess(String response) {
                FreshNewsEvent event=(new Gson()).fromJson(response,FreshNewsEvent.class);
                event.setResultCode(1);
                EventBus.getDefault().post(event);
            }

            @Override
            public void onFail() {
                FreshNewsEvent event=new FreshNewsEvent();
                event.setResultCode(0);
                EventBus.getDefault().post(event);
            }
        });
    }
}
